using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace MyGame
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class GameObject : Microsoft.Xna.Framework.DrawableGameComponent
    {
        public virtual float X
        {
            get { return position.X; }
            set
            {
                if (value < GameGlobals.Margin)
                    position.X = GameGlobals.Margin;
                else if (value > GameGlobals.Width - Texture.Width - GameGlobals.Margin)
                    position.X = GameGlobals.Width - Texture.Width - GameGlobals.Margin;
                else
                    position.X = value;
            }
        }

        public virtual float Y
        {
            get { return position.Y; }
            set
            {
                position.Y = value;
            }
        }

        public Rectangle Bounds
        {
            get { return new Rectangle((int)X+10, (int)Y+5, Texture.Width-20, Texture.Height-10); }
        }

        public bool OutOfScreen
        {
            get { return Y <= -Texture.Height; }
        }

        public Texture2D Texture;

        protected GraphicsDevice device;
        protected SpriteBatch spriteBatch;

        protected Vector2 position;

        public GameObject(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
            device = GameGlobals.graphicsManager.GraphicsDevice;
            spriteBatch = new SpriteBatch(device);
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }
    }
}
